<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="关键词">
                <a-input v-model="queryParam.name" placeholder="请输入关键词" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (this.queryParam = {})">重置</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :border="false">
      <s-table row-key="key" size="default" :columns="columns" :data="loadData" ref="table"> </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
import moment from 'moment'
import { STable } from '@/components'
import { levelOrder } from '@/api/user'

const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '订单号',
    dataIndex: 'order_no',
  },
  {
    title: '昵称',
    dataIndex: 'nickname',
  },
  {
    title: '支付金额',
    dataIndex: 'pay_price',
  },
  {
    title: '购买前',
    dataIndex: 'current_name',
  },
  {
    title: '购买后',
    dataIndex: 'after_name',
  },
  {
    title: '支付日期',
    dataIndex: 'pay_time',
  },
]

export default {
  name: 'LevelOrderRecord',
  components: {
    STable,
  },
  data() {
    return {
      selectDate: null,
      locale: zhCN,
      ranges: {
        一月内: () => [moment().startOf('day').subtract(1, 'month'), moment()],
        昨天: () => [moment().startOf('day').subtract(1, 'days'), moment().endOf('day').subtract(1, 'days')],
        最近一周: () => [moment().startOf('day').subtract(1, 'weeks'), moment()],
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      form: this.$form.createForm(this),
      // 表头
      columns,
      // 权限树
      permissionTree: [],
      modalLoading: false,
      defaultCheckedKeys: [],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        Object.assign(parameter, this.queryParam)
        console.log(parameter)
        return levelOrder(parameter).then((res) => {
          return res.data
        })
      },
      queryParam: {},
    }
  },
  created() {},
  methods: {
    resetSearchForm() {
      this.queryParam = {
        dateStart: moment(new Date()),
        dateEnd: moment(new Date()),
      }
    },
    moment,
    // 选中日期事件
    calendarChange(date, dateString) {
      // if (date.length <= 1) {
      //   // 选中开始日期事件，设置结束日期必须大于1天
      //   this.selectDate = date[0].add(1, 'days')
      // } else {
      //   this.selectDate = null
      // }
      this.selectDate = date[0]
    },
    // 选择后的事件
    onChange(date, dateString) {
      this.queryParam.dateStart = dateString[0]
      this.queryParam.dateEnd = dateString[1]
    },
  },
}
</script>
